#ifndef _BUOLA_GUI_CCHECKWIDGET_H_
#define _BUOLA_GUI_CCHECKWIDGET_H_

#include <buola/widgets/cwidget.h>
#include <buola/utility/uevent.h>

namespace buola { namespace gui {

///\addtogroup widgetclass
///@{

////////////////////////////////////////////////////////////////////////////

/// check widget class

/// this is a base class for widgets that represent a binary value
///
////////////////////////////////////////////////////////////////////////////

class CCheckWidget : public CWidget
{
protected:
//! \name constructor and destructor
//@{
    CCheckWidget()
        :   mCWChecked(false)
    {}

    virtual ~CCheckWidget()
    {}
//@}

public:
//! \name properties
//@{
    void GetPropertyNames(std::vector<std::string> &pNames);
    void SetProperty(const std::string &p,const UAny &v);

//! \name public interface
//@{
    //! check or uncheck the widget
    void Check(bool pCheck=true)
    {
        if(pCheck==mCWChecked)
            return;

        mCWChecked=pCheck;

        OnCWChecked();

        eChecked(mCWChecked);
    }

    //! toggles the state of the widget
    void Toggle()
    {
        Check(!mCWChecked);
    }

    //! returns true if the widget is checked
    bool IsChecked()        {   return mCWChecked;      }
//@}

//! \name interface for reimplementors
//@{
private:
    //! reimplement to keep track of changes
    virtual void OnCWChecked()=0;

protected:
    //! set the value without triggering an update
    void CWCheck(bool pCheck)
    {
        mCWChecked=pCheck;
    }
//@}

public:
//! \name events and signals
//@{
    //! triggered when the value of the slider changes
    UEvent<void(bool)> eChecked;
//@}

private:
    bool mCWChecked;
};

///@}

/*namespace gui*/ } /*namespace buola*/ }

#endif
